// pages/web/college/college.js
var o, page = 1;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    cat_list: [],
    article_list: [],
    cat_checked: true,
    integral_catId:'1',
    page_count:'1',
    keyword:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (t) {
    o = this
    getApp().page.onLoad(this, t);
    o.supershop_cat_list()
  },
  supershop_cat_list: function (e) {
    getApp().request({
      url: getApp().api.default.supershop_cat_list,
      success: function (t) {
        console.log(t)
        if (0 == t.code) {
          t.data[0].cat_checked = true;
          o.setData({
            cat_list: t.data,
            integral_catId:t.data[0].id
          });
          o.supershop_article_list(t.data[0].id,'')
        }
      },
    })
  },
  supershop_article_list: function (e,c) {
    var article_list = o.data.article_list
    getApp().request({
      url: getApp().api.default.supershop_article_list,
      data: {
        cat_id: e,
        page: page,
        keyword:c
      },
      success: function (t) {
        console.log(t)
        if (0 == t.code) {
          for (var s in t.data.list){
            article_list.push(t.data.list[s])
          }
          o.setData({
            article_list: article_list,
            page_count:t.data.page_count
          })
        }
      },
    })
  },
  catGoods: function (t) {
    var e = t.currentTarget.dataset, a = this, n = a.data.cat_list, integral_catId = e.catId;
    console.log('eee', e)
    var o = e.index;
    if (-1 === o) {
      var i = !0;
      for (var s in n) n[s].cat_checked = !1;
    }
    if (0 <= o) for (var s in n) n[s].id == n[o].id ? i = !(n[s].cat_checked = !0) : n[s].cat_checked = !1;
    a.setData({
      article_list:[],
      keyword:'',
      cat_checked: i,
      cat_list: n,
      integral_catId:e.catId
    });
    console.log(a.data)
    page = 1, a.supershop_article_list(integral_catId,'');
  },
  ss:function(e){
    var keyword = e.detail.value
    o.setData({
      keyword:keyword
    })
  },
  sous:function(e){
    o.setData({
      article_list:[],
    })
    page = 1, o.supershop_article_list(o.data.integral_catId,o.data.keyword)
  },
  collegedetails: function (e) {
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '../collegedetails/collegedetails?id=' + id,
    })
  },
  onReachBottom: function (t) {
    var a = this
    console.log(page, Number(a.data.page_count))
    if (page === Number(a.data.page_count)) {
      console.log('到底了+++++++', t)
      getApp().core.showToast({
        title: "没有更多啦",
        icon: "none"
      })
    } else {
      page += 1
      a.supershop_article_list(a.data.integral_catId,a.data.keyword);
    }
  },
})